/*
 * Phase.cpp
 *
 *  Created on: 16/10/2011
 *      Author: godinho
 */

#include <localview/Phase.h>
#include <localview/Link.h>
#include <log.h>

namespace localview {

Phase::Phase() {
    mPrevious = 0;
    mTrasitionPhase = false;
}

Phase::~Phase() {
}

int Phase::addLink(Link* link, char status) {
	mLinks.push_back(link);
	int index = mLinks.size()-1;
	mStatus.push_back('-');
	setStatus(index, status);

	if(status == 'y' || status == 'G') {
	    mPrevious = link->getFrom();
	}

	return index;
}

int Phase::getLinkCount() {
	return mLinks.size();
}

Link* Phase::getLink(int index) {
	return mLinks[index];
}

void Phase::setStatus(const char* status) {
	for(int i = 0; status[i]; i++) {
		setStatus(i, status[i]);
	}
}

void Phase::setStatus(int linkIndex, char status) {
    if(status == 'y') {
        mTrasitionPhase = true;
    }

	mStatus[linkIndex] = status;
}

char Phase::getStatus(int index) {
	return mStatus[index];
}

int Phase::getDuration() {
	return mDuration;
}

void Phase::setDuration(int d) {
	mDuration = d;
}

std::vector<Link*> Phase::getLinks() {
	return mLinks;
}

std::vector<Link*> Phase::getLinksOnStatus(char s) {
	std::vector<Link*> links;

	for(int i = 0; i < mLinks.size(); i++) {
		if(mStatus[i] == s) {
			links.push_back(mLinks[i]);
		}
	}

	return links;
}

Node *Phase::getNext() const
{
    return mNext;
}

Node *Phase::getPrevious() const
{
    return mPrevious;
}

void Phase::setNext(Node *next) {
    mNext = next;
}

bool Phase::isTransitionPhase() {
    return mTrasitionPhase;
}

}
